package com.txy.webmanagement.control;

import com.txy.webmanagement.model.SysMenu;
import com.txy.webmanagement.model.SysUser;
import com.txy.webmanagement.service.SysMenuService;
import com.txy.webmanagement.utils.RequestDataUtils;
import com.txy.webmanagement.utils.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping(value = "home")
public class MainHomeControl {
    @Autowired
    private SysMenuService sysMenuService;


    @RequestMapping(value = "index")
    public String index(Model m) {
        //根据登录用户展示用户 权限
        SysUser user = UserUtils.getLoginUser();
        //获取所有的菜单信息
        String usertType = user.getTypeId();
        List<SysMenu> firstMenulist = sysMenuService.findFirstMenuList(usertType);
        m.addAttribute("menmuList", firstMenulist);
        m.addAttribute("user", user);
        return "mainHome/home";
    }

    /**
     * 查询二级菜单
     *
     * @param parentId
     * @return
     */
    @RequestMapping(value = "getSecondMenuList")
    @ResponseBody
    public RequestDataUtils getSecondMenuList(String parentId) {
        return sysMenuService.findSecendMenuList(parentId);
    }

    @RequestMapping(value = "productList")
    public String productList() {

        return "mainHome/productList";
    }


}
